package wheel;

import wheel.Game.ContestantAction;

public class ReluctantSolver extends Computer {

	public ReluctantSolver(String name, boolean debugMode, int perWordPossibilityThreshold) {
		super(name, debugMode);
		this.perWordPossibilityThreshold = perWordPossibilityThreshold;
	}
	
	public ContestantAction getContestantAction() {

		// Always spin wheel if you can, otherwise buy vowel if you can, else try to solve.
		if (this.currentPuzzle.isMoreConsonants()) {
			System.out.println(Computer.SPIN);
			return Game.ContestantAction.SPIN_WHEEL;
		}
		else if (this.getWinnings() >= 250) {
			System.out.println(Computer.VOWEL);
			return Game.ContestantAction.BUY_VOWEL;
		}
		else {
			prepareToSolve();
			if (!formulateSolution().equals(NO_SOLUTION)) {
				System.out.println(Computer.SOLVE);
				return Game.ContestantAction.SOLVE;
			}
			else return Game.ContestantAction.WAVE_TO_VANNA;
		}
	}
	
	@Override
	public ContestantAction getFreePlayAction() {
		if (this.currentPuzzle.isMoreVowels()) {
				System.out.println("I will take a free vowel.");
				return Game.ContestantAction.FREE_VOWEL;
		}
		else {
			System.out.println("I will take a free consonant.");
			return Game.ContestantAction.FREE_CONSONANT;
		}
	}
	
	public void speak() {
		SoundPlayer audio = new SoundPlayer();
		switch (1 + (int)(Math.random() * 3)) {
		case 1:
			audio.playSound(SoundPlayer.SOUND_FILES_DIRECTORY + "slave.wav");
			break;
		case 2:
			audio.playSound(SoundPlayer.SOUND_FILES_DIRECTORY + "slave2.wav");
			break;
		case 3:
			audio.playSound(SoundPlayer.SOUND_FILES_DIRECTORY + "slave3.wav");
			break;
		}
	}
	
	@Override
	public void learnPuzzle(Puzzle puzzle) {
		// ReluctantSolver doesn't learn.
		return;
	}
}
